using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Daniel.Core.Models.Mapping
{
    public class TierPriceMap : EntityTypeConfiguration<TierPrice>
    {
        public TierPriceMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            // Table & Column Mappings
            this.ToTable("TierPrice");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.ProductId).HasColumnName("ProductId");
            this.Property(t => t.StoreId).HasColumnName("StoreId");
            this.Property(t => t.CustomerRoleId).HasColumnName("CustomerRoleId");
            this.Property(t => t.Quantity).HasColumnName("Quantity");
            this.Property(t => t.Price).HasColumnName("Price");

            // Relationships
            this.HasOptional(t => t.CustomerRole)
                .WithMany(t => t.TierPrices)
                .HasForeignKey(d => d.CustomerRoleId);
            this.HasRequired(t => t.Product)
                .WithMany(t => t.TierPrices)
                .HasForeignKey(d => d.ProductId);

        }
    }
}
